package com.itheima.stock.controller;

import com.itheima.stock.common.domian.UpdateUserAndRoleInfoDomain;
import com.itheima.stock.common.domian.UserAddDomain;
import com.itheima.stock.common.domian.UserAndRoles;
import com.itheima.stock.pojo.SysUser;
import com.itheima.stock.service.UserService;
import com.itheima.stock.vo.result.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: siwukun
 * @date: 2022/06/10
 * @description:
 */
@RestController
@RequestMapping("/api/user")
public class UserRolesController {
    @Autowired
    private UserService userService;

    /**
     * 获取用户具有的角色信息接口说明
     *
     * @param userId
     * @return
     */
    @GetMapping("/roles/{userId}")
    public R<UserAndRoles> getAllUserRoles(@PathVariable String userId) {

        return userService.queryAllUserRoles(userId);
    }


    /**
     * 更新用户角色信息接口
     *
     * @param updateUserAndRoleInfoDomain id实体类
     * @return
     */
    @PutMapping("/roles")
    public R<String> updateAllUsers(@RequestBody UpdateUserAndRoleInfoDomain updateUserAndRoleInfoDomain) {
        return userService.updateAllUsers(updateUserAndRoleInfoDomain);
    }

    /**
     * 批量删除用户信息
     *
     * @param userIds 用户id
     * @return
     */
    @DeleteMapping
    public R<String> deleteALLUserInfo(@RequestBody List<Long> userIds) {

        return userService.deleteALLUserInfo(userIds);
    }

    /**
     * 根据用户id查询用户信息
     *
     * @param id 用户id
     * @return
     */
    @GetMapping("/info/{userId}")
    public R<SysUser> getUserById(@PathVariable Long id) {
        return userService.getUserById(id);
    }

    @PutMapping
    public R<String> updateUserById(@RequestBody UserAddDomain userAddDomain) {
        return userService.updateUserById(userAddDomain);
    }

}
